//
//  UIImage+Render.m
//  主流框架的搭建
//
//  Created by 辛路琦 on 16/5/25.
//  Copyright © 2016年 辛路琦. All rights reserved.
//

#import "UIImage+Render.h"

@implementation UIImage (Render)

+ (UIImage *)imageWithOriginal:(NSString *)imageName
{
    UIImage *image = [UIImage imageNamed:imageName];
    return [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}

+ (UIImage *)imageWithOvalInRect:(UIImage *)image
{
    // 1.开启位图上下文
    // scale:比例因素 点:像素比例 0:自动识别比例因素
    UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);
    
    // 2.描述圆形裁剪路径
    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width , image.size.height)];
    
    // 3.设置裁剪区域,裁剪区域一定要先设置,在绘图
    [path addClip];
    
    // 4.画图片
    [image drawAtPoint:CGPointZero];
    
    // 5.从上下文中取出图片
    image = UIGraphicsGetImageFromCurrentImageContext();
    
    // 6.关闭上下文
    UIGraphicsEndImageContext();
    
    return image;
}

@end
